package com.yjz.jvm.java8.stream;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
public class StreamTest {

  @Test
  public void test01() {
    List<Student> studentList = new ArrayList<>();
    studentList.add(Student.builder().age("21").name("张三").sexy("男").build());
    studentList.add(Student.builder().age("22").name("李四").sexy("男").build());
    studentList.add(Student.builder().age("29").name("王五").sexy("男").build());
    studentList.add(Student.builder().age("27").name("亚索").sexy("男").build());
    studentList.add(Student.builder().age("19").name("卡特").sexy("女").build());
    //找出女学生
    List<Student> list = studentList.stream().filter(v -> v.getSexy().equals("女")).collect(Collectors.toList());
    log.info(list.toString());
    //找出所有学生性别
    List<String> sexList = studentList.stream().map(student -> student.getSexy()).collect(Collectors.toList());
    log.info(sexList.toString());
    //找出所有学生的性别
    List<String> sexList2 = studentList.stream().map(Student::getSexy).collect(Collectors.toList());
    log.info(sexList2.toString());
  }
}
